package com.kuang.queue;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

public class SynchronousQueue1 {
    public static void main(String[] args) {
        SynchronousQueue<String> queue = new SynchronousQueue<>();



        new Thread(()->{

            try {
                queue.put("1");
                System.out.println(Thread.currentThread().getName()+"插入1");
                TimeUnit.SECONDS.sleep(2);
                queue.put("2");
                System.out.println(Thread.currentThread().getName()+"插入2");
                TimeUnit.SECONDS.sleep(2);
                queue.put("3");
                System.out.println(Thread.currentThread().getName()+"插入3");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"T1").start();

        new Thread(()->{

            try {
                TimeUnit.SECONDS.sleep(4);

                System.out.println(Thread.currentThread().getName()+"取出"+ queue.take());
                TimeUnit.SECONDS.sleep(2);
                System.out.println(Thread.currentThread().getName()+"取出"+ queue.take());
                TimeUnit.SECONDS.sleep(2);
                System.out.println(Thread.currentThread().getName()+"取出"+ queue.take());
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {


            }
        },"T2").start();
    }
}
